#ifndef _SDLWINDOW_H_
#define _SDLWINDOW_H_

#include <SECore/Window.h>
#include <string>
#include <SECore/Signal.h>


union SDL_Event;
struct SDL_Window;

namespace SEngine
{

    enum SDLWindowFlags : uint32_t
    {
        SE_WINDOW_FULLSCREEN           = 0x00000001,   /**< window is in fullscreen mode */
        SE_WINDOW_OPENGL               = 0x00000002,   /**< window usable with OpenGL context */
        SE_WINDOW_OCCLUDED             = 0x00000004,   /**< window is occluded */
        SE_WINDOW_HIDDEN               = 0x00000008,   /**< window is neither mapped onto the desktop nor shown in the taskbar/dock/window list; SDL_ShowWindow() is required for it to become visible */
        SE_WINDOW_BORDERLESS           = 0x00000010,   /**< no window decoration */
        SE_WINDOW_RESIZABLE            = 0x00000020,   /**< window can be resized */
        SE_WINDOW_MINIMIZED            = 0x00000040,   /**< window is minimized */
        SE_WINDOW_MAXIMIZED            = 0x00000080,   /**< window is maximized */
        SE_WINDOW_MOUSE_GRABBED        = 0x00000100,   /**< window has grabbed mouse input */
        SE_WINDOW_INPUT_FOCUS          = 0x00000200,   /**< window has input focus */
        SE_WINDOW_MOUSE_FOCUS          = 0x00000400,   /**< window has mouse focus */
        SE_WINDOW_FOREIGN              = 0x00000800,   /**< window not created by SDL */
        SE_WINDOW_HIGH_PIXEL_DENSITY   = 0x00002000,   /**< window uses high pixel density back buffer if possible */
        SE_WINDOW_MOUSE_CAPTURE        = 0x00004000,   /**< window has mouse captured (unrelated to MOUSE_GRABBED) */
        SE_WINDOW_ALWAYS_ON_TOP        = 0x00008000,   /**< window should always be above others */
        SE_WINDOW_UTILITY              = 0x00020000,   /**< window should be treated as a utility window, not showing in the task bar and window list */
        SE_WINDOW_TOOLTIP              = 0x00040000,   /**< window should be treated as a tooltip and must be created using SDL_CreatePopupWindow() */
        SE_WINDOW_POPUP_MENU           = 0x00080000,   /**< window should be treated as a popup menu and must be created using SDL_CreatePopupWindow() */
        SE_WINDOW_KEYBOARD_GRABBED     = 0x00100000,   /**< window has grabbed keyboard input */
        SE_WINDOW_VULKAN               = 0x10000000,   /**< window usable for Vulkan surface */
        SE_WINDOW_METAL                = 0x20000000,   /**< window usable for Metal view */
        SE_WINDOW_TRANSPARENT          = 0x40000000    /**< window with transparent buffer */
    };

    struct SDLInitHelper; 
    class SDLWindow : public Window
    {
    public:
        friend struct SDLInitHelper; 
    public:
        SDLWindow(const std::string & title, int w, int h, uint32_t flags);
        virtual ~SDLWindow();

        void PollEvent(EventHandler && fn) override;
        void SwapBuffer() override;
        std::pair<int, int> GetWindowSize() override; 


        SDL_Window * GetWindow() { return m_window; }
    
    private:
        SDL_Window * m_window;
        std::unique_ptr<SDLInitHelper> m_sdlInitHelper;
    
    public:
        inline static void * g_glContext;
        Signal<SDL_Event&> eventSignal;

    };
} // namespace SEgine


#endif